package com.thenie.service.impl;

import com.thenie.mapper.MenuMapper;
import com.thenie.pojo.Menu;
import com.thenie.service.MenuService;
import com.thenie.vo.MenuVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class MenuServiceImpl implements MenuService {

    @Resource
    private MenuMapper menuMapper;

    public List<Menu> findAllMenuList() {
        return menuMapper.findAllMenuList();
    }

    /**
     * 查询角色下有哪些菜单功能
     * @param roleId
     * @return 返回菜单的ID集合
     */
    public List<Integer> findMenuIdListByRoleId(int roleId){
        return menuMapper.findMenuIdListByRoleId(roleId);
    }

    /**
     * 查询员工拥有的菜单
     * @param employeeId
     * @return
     */
    public List<Menu> findMenuListByEmpId(int employeeId){
        return menuMapper.findMenuListByEmpId(employeeId);
    }
    /**
     * 查询菜单列表
     * @param menuVo
     * @return
     */
    public List<Menu> findMenuListByPage(MenuVo menuVo){
        return menuMapper.findMenuListByPage(menuVo);
    }

    /**
     * 修改菜单数据
     * @param menu
     * @return
     */
    public int updateMenu(Menu menu){
        return menuMapper.updateMenu(menu);
    }


    /**
     * 删除菜单
     * @param menuId
     * @return
     */
    public int deleteMenu(int menuId) {
        int hasChildCount = menuMapper.findChildMenuCountByMenuId(menuId);//查询拥有子菜单的数量
        if (hasChildCount>0){//返回0，不能删除
            return 0;
        }else{//删除
            menuMapper.deleteRoleMenuByMenuId(menuId);
            return menuMapper.deleteMenuById(menuId);
        }
    }


}
